<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Docker Compose学习 | 飞の博客</title><meta name="author" content="Fei"><meta name="copyright" content="Fei"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="Docker Compose学习">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker Compose学习">
<meta property="og:url" content="https://tengfei2233.gitee.io/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="飞の博客">
<meta property="og:description" content="Docker Compose学习">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg">
<meta property="article:published_time" content="2023-08-27T15:34:50.000Z">
<meta property="article:modified_time" content="2023-08-27T15:34:50.000Z">
<meta property="article:author" content="Fei">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg"><link rel="shortcut icon" href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/icon.png"><link rel="canonical" href="https://tengfei2233.gitee.io/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="msvalidate.01" content="2ADFA30867CBC6E090E3C5B244DC311D"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.3.0/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?07a1f58fb95d3d4a97c2ae0a181c9964";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.staticfile.org/flickr-justified-gallery/2.1.2/fjGallery.min.js',
      css: 'https://cdn.staticfile.org/flickr-justified-gallery/2.1.2/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Docker Compose学习',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-08-27 23:34:50'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/fei.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">24</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="飞の博客"><span class="site-name">飞の博客</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Docker Compose学习</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-08-27T15:34:50.000Z" title="发表于 2023-08-27 23:34:50">2023-08-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-27T15:34:50.000Z" title="更新于 2023-08-27 23:34:50">2023-08-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Docker/">Docker</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.8k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Docker Compose学习"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="Docker-Compose学习"><a href="#Docker-Compose学习" class="headerlink" title="Docker Compose学习"></a>Docker Compose学习</h2><h3 id="Docker-Compose是什么"><a href="#Docker-Compose是什么" class="headerlink" title="Docker Compose是什么"></a>Docker Compose是什么</h3><blockquote>
<p>Docker Compose是一个用于定义和管理多个Docker容器的工具，Docker Compose项目由Python编写，调用Docker服务提供的API来对容器进行管理。</p>
<p>docker-compose.yml是Docker Compose工具使用的配置文件，它是一个YML&#x2F;YAML格式的文件，用于描述应用程序的组件和它们之间的关系。在这个文件中，你可以定义多个服务，每个服务对应一个容器，并指定容器的镜像、端口映射、环境变量等配置。</p>
</blockquote>
<h3 id="为什么要使用Docker-Compose"><a href="#为什么要使用Docker-Compose" class="headerlink" title="为什么要使用Docker Compose"></a>为什么要使用Docker Compose</h3><blockquote>
<ol>
<li><strong>简化多容器应用部署：</strong>Docker Compose 允许你使用一个文件来定义和管理多个容器，而不需要手动编写大量的 Docker 命令。这样可以大大简化多容器应用的部署过程，减少人工错误。</li>
<li><strong>统一的环境描述：</strong>使用 Docker Compose，你可以将应用程序的各个组件的配置集中在一个文件中，包括容器镜像、端口映射、环境变量等。这样可以确保在不同环境（开发、测试、生产）之间具有一致的配置，避免了手动配置的差异性。</li>
<li><strong>快速启动和停止应用</strong>：通过运行 <code>docker-compose up</code> 命令，Docker Compose 可以自动创建、启动和连接多个容器。这使得应用的启动过程变得非常简单和快速。而使用 <code>docker-compose down</code> 命令可以快速停止并清理所有相关的容器和资源。</li>
<li><strong>容器间的依赖管理：</strong>Docker Compose 允许你在配置文件中指定容器之间的依赖关系。这意味着你可以确保在启动应用程序时，所有依赖的容器都会正确启动，并按照指定的顺序进行启动。</li>
<li><strong>可扩展性和复用性：</strong>Docker Compose 允许你定义多个服务，并将它们组合成一个应用程序。这样，你可以轻松地扩展应用程序，添加新的服务或复制现有的服务。此外，你还可以将已定义的服务组合成一个模板，并在不同的项目中重复使用。</li>
</ol>
<p>假设有这么一个场景，你开发了一个web服务，这个web服务涉及到了前端，后端，Nginx，数据库，缓存，消息队列，搜索引擎等，现在需要将这些服务部署到Docker上，如果一个一个部署的话，以现在的体量，可能还好，当服服务达到几十上百个的时候，你要对这些服务进行部署，启动，停止，容器间连接，效率就会非常慢；你可能会说，我可以把这些都部署到一个容器中啊！</p>
<p>你说的不错，的确都可以都部署到一个容器中；但是当服务需要做分布式的时候，显然是不能将所以服务都部署到一个服务中的，像数据库集群，缓存集群做起来就会非常麻烦；还有就是将所有服务都部署到一个容器中，这不变成直接再服务器上部署，失去了Docker的便利性了。</p>
<p>总的来说，使用 Docker Compose 可以简化多容器应用的部署和管理过程，提高开发效率，确保环境的一致性，并提供了容器间依赖管理和可扩展性的优势。它是一个强大的工具，特别适用于构建和管理复杂的应用程序架构。</p>
<p>以下就针对docker-compose的编写规范，指令详解，以及针对一个应用示例进行说明。</p>
</blockquote>
<h3 id="docker-compose-yml的文件指令详解"><a href="#docker-compose-yml的文件指令详解" class="headerlink" title="docker-compose.yml的文件指令详解"></a>docker-compose.yml的文件指令详解</h3><blockquote>
<p>按照YML文件的格式，docker-compose.yml文件包含四个常见的一级key：version、services、networks、volumes，以及还有几个不常见的，configs、secrets</p>
<p><strong>version：</strong> 必须指定的，而且总是位于文件的第一行。它定义了 compose 文件格式(主要是 API)的版本。注意，version 并非定义 Docker Compose 或 Docker 引擎的版本号。基本上就是定义你这一系列服务的版本。</p>
<p><strong>services：</strong> 用于定义不同的容器服务，每个服务都是一个容器。比如数据库服务、后端服务、网关服务等，每个服务占用一个二级标签。</p>
<p><strong>networks：</strong> 用于自定义docker虚拟网桥，将指定容器链接在这个网络下，这个容器间就可以通过网桥名称:端口访问对于的容器了。</p>
<p><strong>volumes：</strong> 用于指引 Docker 来创建新的卷，卷的作用就是容器间共享数据，然后将卷映射到外部宿主机。</p>
<p><strong>configs：</strong>定义要创建的配置及其配置，配置用于将文件或配置数据传递给服务容器。</p>
<p><strong>secrets：</strong>定义要创建的密钥及其配置。密钥用于安全地传递敏感信息给服务容器。</p>
</blockquote>
<h4 id="version"><a href="#version" class="headerlink" title="version"></a>version</h4><figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 版本1.2.3，只当前docker-compose的版本</span></span><br><span class="line"><span class="attr">version:</span> <span class="string">&#x27;1.2.3&#x27;</span></span><br></pre></td></tr></table></figure>

<h4 id="services"><a href="#services" class="headerlink" title="services"></a>services</h4><ul>
<li>services也是docker-compose最主要的部分，也是重点要关注的部分，services下每一个二级标签都是一个服务(容器)</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">services:</span> </span><br><span class="line">  <span class="comment"># web服务</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">  	<span class="comment"># web服务的镜像</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">nginx:latest</span></span><br><span class="line">    <span class="comment"># 容器名称</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">nginx-client</span></span><br><span class="line">    <span class="comment"># 暴露的端口</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;80:80&quot;</span></span><br><span class="line">    <span class="comment"># 挂载的卷，映射的目录，容器内/usr/share/nginx/html映射到当前目录html下</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./html:/usr/share/nginx/html</span></span><br><span class="line">    <span class="comment"># 网络，处于docker自定义的frontend网卡下</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">frontend</span></span><br><span class="line">  <span class="comment"># api服务</span></span><br><span class="line">  <span class="attr">api:</span></span><br><span class="line">  	<span class="comment"># 这里没有使用image，则是使用当前目录的api目录下的Dockerfile来构建镜像</span></span><br><span class="line">  	<span class="comment"># 容器名称</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">back-api</span></span><br><span class="line">    <span class="attr">build:</span></span><br><span class="line">      <span class="attr">context:</span> <span class="string">./api</span></span><br><span class="line">      <span class="attr">dockerfile:</span> <span class="string">Dockerfile</span></span><br><span class="line">    <span class="comment"># 暴露端口</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;8080:8080&quot;</span></span><br><span class="line">     <span class="comment"># 依赖于下面的的db服务，这样只有在db服务启动后，这个服务才会启动</span></span><br><span class="line">     <span class="comment"># 注意：这个在之db后只是说db服务已经启动，不一定是可用的，如果db服务启动了，但是不可以，api服务还是会启动的</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">db</span></span><br><span class="line">    <span class="comment"># 网络，连接到多个网络，或者说连接到多个docker虚拟网桥</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">frontend</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">backend</span></span><br><span class="line">  <span class="comment"># db服务</span></span><br><span class="line">  <span class="attr">db:</span></span><br><span class="line">   <span class="comment"># 启动镜像</span></span><br><span class="line">   <span class="attr">image:</span> <span class="string">mysql:latest</span></span><br><span class="line">   <span class="comment"># 容器名称</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">m</span></span><br><span class="line">   <span class="comment"># 环境变量</span></span><br><span class="line">   <span class="attr">environment:</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">MYSQL_ROOT_PASSWORD=secret</span></span><br><span class="line">   <span class="comment"># 挂载的卷，这个dbdata不是一个路径，注意了，是一个卷</span></span><br><span class="line">   <span class="attr">volumes:</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">dbdata:/var/lib/mysql</span></span><br><span class="line">   <span class="comment"># 连接到的网络</span></span><br><span class="line">   <span class="attr">networks:</span></span><br><span class="line">     <span class="bullet">-</span> <span class="string">backend</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 这个下面就是指定卷，dbdata这个卷没有指定路径，就是一个匿名卷，匿名卷的路径一般在宿主机该目录下：/var/lib/docker/volumes</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">dbdata:</span></span><br><span class="line"><span class="comment"># 这下面就是定义自定义网桥</span></span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="attr">frontend:</span></span><br><span class="line">  <span class="attr">backend:</span></span><br></pre></td></tr></table></figure>

<h4 id="networks"><a href="#networks" class="headerlink" title="networks"></a>networks</h4><ul>
<li>自定义docker-compose网桥</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="comment"># 自定义名为mynetwork的网桥</span></span><br><span class="line">  <span class="attr">mynetwork:</span></span><br><span class="line">    <span class="comment"># 网络模式为bridge</span></span><br><span class="line">    <span class="attr">driver:</span> <span class="string">bridge</span></span><br><span class="line">    <span class="comment"># 定 IP 地址管理驱动程序为 default，default 是 Docker 默认的 IP 地址管理驱动程序，它负责为容器分配 IP 地址</span></span><br><span class="line">    <span class="attr">ipam:</span></span><br><span class="line">      <span class="attr">driver:</span> <span class="string">default</span></span><br><span class="line">	  <span class="comment"># 指定 IP 地址配置的详细信息。</span></span><br><span class="line">      <span class="attr">config:</span></span><br><span class="line">      	  <span class="comment"># 子网掩码</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">subnet:</span> <span class="number">172.20</span><span class="number">.0</span><span class="number">.0</span><span class="string">/16</span></span><br><span class="line">       	  <span class="comment"># 网关地址</span></span><br><span class="line">          <span class="attr">gateway:</span> <span class="number">172.20</span><span class="number">.0</span><span class="number">.1</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>dirver为定义网络的类型，以下是几种不同的网络类型</p>
<ul>
<li><p><strong>bridge</strong>：这是 Docker 默认的网络驱动程序。它使用 Docker 守护进程的网络桥接功能，允许容器通过宿主机的网络进行通信。<code>bridge</code> 驱动程序适用于大多数常见的应用场景，基本上自定义网桥都是使用bridge类型。</p>
</li>
<li><p><strong>host</strong>：使用 <code>host</code> 驱动程序时，容器将与宿主机共享网络命名空间。这意味着容器将直接使用宿主机的网络接口，而不会创建自己的网络栈。使用 <code>host</code> 驱动程序可以实现与宿主机相同的网络性能，但容器之间的网络隔离性较差。相当于容器就是宿主机上的一个应用，使用宿主机的网络。</p>
</li>
<li><p><strong>overlay</strong>：<code>overlay</code> 驱动程序允许在多个 Docker 主机之间创建跨主机的网络。它适用于构建分布式应用程序和容器集群，允许容器在不同的主机上进行通信。</p>
</li>
<li><p><strong>macvlan</strong>：<code>macvlan</code> 驱动程序允许为容器分配与宿主机相同的 MAC 地址，使容器能够直接与物理网络进行通信。这对于需要与物理网络进行直接交互的应用程序非常有用。</p>
</li>
<li><p><strong>ipvlan</strong>：<code>ipvlan</code> 驱动程序类似于 <code>macvlan</code>，但它允许为容器分配不同的 IP 地址。这使得容器可以直接与物理网络进行通信，并具有与宿主机不同的 IP 地址。这相当于是另一台与宿主机在同一网络下的机器。</p>
</li>
</ul>
</li>
</ul>
<h4 id="volumes"><a href="#volumes" class="headerlink" title="volumes"></a>volumes</h4><ul>
<li>创建卷，也就是在宿主机上创建一个多容器共享的文件夹</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="comment"># 卷一，没有指定卷在宿主机的路径，默认在/var/lib/docker/volumes下</span></span><br><span class="line">  <span class="attr">myvolume1:</span></span><br><span class="line">  <span class="comment"># 卷二，使用local驱动(默认)，</span></span><br><span class="line">  <span class="attr">myvolume2:</span></span><br><span class="line">    <span class="attr">driver:</span> <span class="string">local</span></span><br><span class="line">    <span class="attr">driver_opts:</span></span><br><span class="line">      <span class="comment"># 不适用特定驱动类型</span></span><br><span class="line">      <span class="attr">type:</span> <span class="string">none</span></span><br><span class="line">      <span class="comment"># 改卷在/app/volumes/目录下</span></span><br><span class="line">      <span class="attr">device:</span> <span class="string">/app/volumes/</span></span><br></pre></td></tr></table></figure>

<h4 id="configs"><a href="#configs" class="headerlink" title="configs"></a>configs</h4><figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">version:</span> <span class="string">&#x27;3&#x27;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">service1:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">image1</span></span><br><span class="line">    <span class="attr">configs:</span></span><br><span class="line">        <span class="comment"># 将这个配置设置到这个容器的/app/config/目录</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">myconfig:/app/config/</span></span><br><span class="line"><span class="comment"># 创建一个配置</span></span><br><span class="line"><span class="attr">configs:</span></span><br><span class="line">  <span class="comment"># 配置地址</span></span><br><span class="line">  <span class="attr">myconfig:</span></span><br><span class="line">    <span class="comment"># 配置文件名称</span></span><br><span class="line">    <span class="attr">file:</span> <span class="string">./config.txt</span></span><br></pre></td></tr></table></figure>

<h4 id="secrets（具体还不知道有啥用，以后再研究，不过者指令也基本上用的非常少）"><a href="#secrets（具体还不知道有啥用，以后再研究，不过者指令也基本上用的非常少）" class="headerlink" title="secrets（具体还不知道有啥用，以后再研究，不过者指令也基本上用的非常少）"></a>secrets（具体还不知道有啥用，以后再研究，不过者指令也基本上用的非常少）</h4><figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">version:</span> <span class="string">&#x27;3.1&#x27;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">service1:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">image1</span></span><br><span class="line">    <span class="attr">secrets:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">mysecret</span></span><br><span class="line"><span class="comment"># 创建一个密钥</span></span><br><span class="line"><span class="attr">secrets:</span></span><br><span class="line">  <span class="attr">mysecret:</span></span><br><span class="line">    <span class="attr">file:</span> <span class="string">./mysecret.txt</span></span><br></pre></td></tr></table></figure>

<h3 id="根据上文创建的Dockerfile，创建一个docker-compose-yml整合整个系统（实战）"><a href="#根据上文创建的Dockerfile，创建一个docker-compose-yml整合整个系统（实战）" class="headerlink" title="根据上文创建的Dockerfile，创建一个docker-compose.yml整合整个系统（实战）"></a>根据上文创建的Dockerfile，创建一个docker-compose.yml整合整个系统（实战）</h3><ul>
<li><p>在linux上拉取，<a target="_blank" rel="noopener" href="https://github.com/tengfei2233/wangBook.git">项目地址</a></p>
</li>
<li><p>进入docker文件夹，里面有个docker-compose.yml文件，该docker-compose.yml整合了一个后端，两个前端，数据库，缓存。</p>
</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 版本</span></span><br><span class="line"><span class="attr">version:</span> <span class="string">&#x27;1.0.0&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 服务列表 </span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="comment"># 后端</span></span><br><span class="line">  <span class="attr">after-end:</span></span><br><span class="line">    <span class="comment"># 根据该目录下的Dockerfile构建</span></span><br><span class="line">    <span class="attr">build:</span></span><br><span class="line">      <span class="attr">context:</span> <span class="string">../after-end</span></span><br><span class="line">      <span class="attr">dockerfile:</span> <span class="string">Dockerfile</span></span><br><span class="line">    <span class="comment"># 指定构建生成的镜像的名称，与build指令一起存在的话，这个image就是指定构建好镜像的名称以及标签</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">after-end:v1.0</span></span><br><span class="line">    <span class="comment"># 指定容器名称为after-end</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">after-end</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="number">8080</span><span class="string">:8888</span></span><br><span class="line">    <span class="comment"># 关联的网络</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">frontend</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">backend</span></span><br><span class="line">    <span class="comment"># 依赖于db与cache服务</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">db</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">cache</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># 前端用户端</span></span><br><span class="line">  <span class="attr">front-client:</span></span><br><span class="line">    <span class="attr">build:</span> <span class="string">../client</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">front-client:v1.0</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">front-client</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="number">81</span><span class="string">:80</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./nginx/client/nginx.conf:/etc/nginx/nginx.conf</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">frontend</span></span><br><span class="line">    <span class="comment"># 依赖于after-end服务</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">after-end</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># 前端管理端</span></span><br><span class="line">  <span class="attr">front-manage:</span></span><br><span class="line">    <span class="attr">build:</span> <span class="string">../manage</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">front-manage:v1.0</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">front-manage</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="number">82</span><span class="string">:80</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./nginx/manage/nginx.conf:/etc/nginx/nginx.conf</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">frontend</span></span><br><span class="line">    <span class="comment"># 依赖于after-end服务</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">after-end</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># 数据库</span></span><br><span class="line">  <span class="attr">db:</span></span><br><span class="line">    <span class="comment"># 依赖镜像创建容器，当镜像不存在时，便从远程下载</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">mysql:8.0.22</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">mysql8</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="number">3306</span><span class="string">:3306</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./mysql/log:/var/log/mysql</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./mysql/data:/var/lib/mysql</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./mysql/conf:/etc/mysql/conf.d</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">MYSQL_ROOT_PASSWORD=123456</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">backend</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment"># redis缓存</span></span><br><span class="line">  <span class="attr">cache:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">redis:6.2.12</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">redis6</span></span><br><span class="line">    <span class="comment"># 运行时指令，指定配置文件</span></span><br><span class="line">    <span class="attr">command:</span> <span class="string">redis-server</span> <span class="string">/etc/redis/redis.conf</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./redis/data:/data</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./redis/conf/redis.conf:/etc/redis/redis.conf</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="number">6379</span><span class="string">:6379</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">backend</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 自定义docker网络</span></span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="attr">frontend:</span></span><br><span class="line">  <span class="attr">backend:</span></span><br></pre></td></tr></table></figure>

<ul>
<li>在docker目录下执行<code>docker-compose up -d</code>执行docker-compose.yml脚本，因为docker-compose正好在该目录下，所有不需要加上便可执行。</li>
</ul>
<h3 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h3><p><strong>关于docker-compose.yml中的指令，以上已经涉及到了大部分常用的，如果还有一些细节部分可以上<a target="_blank" rel="noopener" href="https://docs.docker.com/compose/">Docker Compose官方文档</a>上查看</strong></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://tengfei2233.gitee.io">Fei</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://tengfei2233.gitee.io/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/">https://tengfei2233.gitee.io/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://tengfei2233.gitee.io" target="_blank">飞の博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Docker/">Docker</a></div><div class="post_share"><div class="social-share" data-image="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/wechat.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/alipay.png" target="_blank"><img class="post-qr-code-img" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/alipay.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Dockerfile学习</div></div></a></div><div class="next-post pull-right"><a href="/2023/11/10/%E5%9C%A8Ubuntu20%E4%B8%8A%E5%AE%89%E8%A3%85CUDA-cuDNN-Miniconda%E7%8E%AF%E5%A2%83(%E5%85%B6%E5%AE%83%E7%B3%BB%E7%BB%9F%E5%90%8C%E7%90%86)/" title="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/ai.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/8/27/Docker%E5%9F%BA%E7%A1%80%E5%AD%A6%E4%B9%A0%E6%96%87%E6%A1%A3-%E5%8C%85%E6%8B%AC%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/" title="Docker基础学习文档(包括安装教程)"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-08-27</div><div class="title">Docker基础学习文档(包括安装教程)</div></div></a></div><div><a href="/2023/6/26/Docker%E5%AE%89%E8%A3%85%E4%B8%80%E4%BA%9B%E5%B8%B8%E7%94%A8%E8%BD%AF%E4%BB%B6%EF%BC%88%E6%9B%B4%E6%96%B0%E4%B8%AD-%EF%BC%89/" title="Docker安装一些常用软件（更新中！）"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-07-31</div><div class="title">Docker安装一些常用软件（更新中！）</div></div></a></div><div><a href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-08-27</div><div class="title">Dockerfile学习</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/fei.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Fei</div><div class="author-info__description">当你想起来了，那就记录一点吧</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">24</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/tengfei2233" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://gitee.com/tengfei2233" target="_blank" title="Gitee"><i class="fab fa-git"></i></a><a class="social-icon" href="/youfeige@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">当你迷茫的时候，那就静下心想想吧！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker-Compose%E5%AD%A6%E4%B9%A0"><span class="toc-number">1.</span> <span class="toc-text">Docker Compose学习</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Docker-Compose%E6%98%AF%E4%BB%80%E4%B9%88"><span class="toc-number">1.1.</span> <span class="toc-text">Docker Compose是什么</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E4%BD%BF%E7%94%A8Docker-Compose"><span class="toc-number">1.2.</span> <span class="toc-text">为什么要使用Docker Compose</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#docker-compose-yml%E7%9A%84%E6%96%87%E4%BB%B6%E6%8C%87%E4%BB%A4%E8%AF%A6%E8%A7%A3"><span class="toc-number">1.3.</span> <span class="toc-text">docker-compose.yml的文件指令详解</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#version"><span class="toc-number">1.3.1.</span> <span class="toc-text">version</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#services"><span class="toc-number">1.3.2.</span> <span class="toc-text">services</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#networks"><span class="toc-number">1.3.3.</span> <span class="toc-text">networks</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#volumes"><span class="toc-number">1.3.4.</span> <span class="toc-text">volumes</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#configs"><span class="toc-number">1.3.5.</span> <span class="toc-text">configs</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#secrets%EF%BC%88%E5%85%B7%E4%BD%93%E8%BF%98%E4%B8%8D%E7%9F%A5%E9%81%93%E6%9C%89%E5%95%A5%E7%94%A8%EF%BC%8C%E4%BB%A5%E5%90%8E%E5%86%8D%E7%A0%94%E7%A9%B6%EF%BC%8C%E4%B8%8D%E8%BF%87%E8%80%85%E6%8C%87%E4%BB%A4%E4%B9%9F%E5%9F%BA%E6%9C%AC%E4%B8%8A%E7%94%A8%E7%9A%84%E9%9D%9E%E5%B8%B8%E5%B0%91%EF%BC%89"><span class="toc-number">1.3.6.</span> <span class="toc-text">secrets（具体还不知道有啥用，以后再研究，不过者指令也基本上用的非常少）</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%B9%E6%8D%AE%E4%B8%8A%E6%96%87%E5%88%9B%E5%BB%BA%E7%9A%84Dockerfile%EF%BC%8C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AAdocker-compose-yml%E6%95%B4%E5%90%88%E6%95%B4%E4%B8%AA%E7%B3%BB%E7%BB%9F%EF%BC%88%E5%AE%9E%E6%88%98%EF%BC%89"><span class="toc-number">1.4.</span> <span class="toc-text">根据上文创建的Dockerfile，创建一个docker-compose.yml整合整个系统（实战）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A1%A5%E5%85%85"><span class="toc-number">1.5.</span> <span class="toc-text">补充</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/11/21/netty%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%EF%BC%8C%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-%E6%9B%B4%E6%96%B0%E4%B8%AD/" title="netty的基本使用，基本原理分析，相关问题解(更新中...)"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/netty-ai.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="netty的基本使用，基本原理分析，相关问题解(更新中...)"/></a><div class="content"><a class="title" href="/2023/11/21/netty%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%EF%BC%8C%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-%E6%9B%B4%E6%96%B0%E4%B8%AD/" title="netty的基本使用，基本原理分析，相关问题解(更新中...)">netty的基本使用，基本原理分析，相关问题解(更新中...)</a><time datetime="2023-11-21T09:27:51.000Z" title="发表于 2023-11-21 17:27:51">2023-11-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/10/%E5%9C%A8conda%E7%8E%AF%E5%A2%83%E4%B8%8B%E8%BF%90%E8%A1%8Cstable-diffusion-webui-AI%E7%BB%98%E5%9B%BE/" title="在conda环境下运行stable-diffusion-webui AI绘图"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/ai.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="在conda环境下运行stable-diffusion-webui AI绘图"/></a><div class="content"><a class="title" href="/2023/11/10/%E5%9C%A8conda%E7%8E%AF%E5%A2%83%E4%B8%8B%E8%BF%90%E8%A1%8Cstable-diffusion-webui-AI%E7%BB%98%E5%9B%BE/" title="在conda环境下运行stable-diffusion-webui AI绘图">在conda环境下运行stable-diffusion-webui AI绘图</a><time datetime="2023-11-10T07:30:51.000Z" title="发表于 2023-11-10 15:30:51">2023-11-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/10/%E5%9C%A8Ubuntu20%E4%B8%8A%E5%AE%89%E8%A3%85CUDA-cuDNN-Miniconda%E7%8E%AF%E5%A2%83(%E5%85%B6%E5%AE%83%E7%B3%BB%E7%BB%9F%E5%90%8C%E7%90%86)/" title="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/ai.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)"/></a><div class="content"><a class="title" href="/2023/11/10/%E5%9C%A8Ubuntu20%E4%B8%8A%E5%AE%89%E8%A3%85CUDA-cuDNN-Miniconda%E7%8E%AF%E5%A2%83(%E5%85%B6%E5%AE%83%E7%B3%BB%E7%BB%9F%E5%90%8C%E7%90%86)/" title="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)">在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)</a><time datetime="2023-11-10T07:27:51.000Z" title="发表于 2023-11-10 15:27:51">2023-11-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/" title="Docker Compose学习"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Docker Compose学习"/></a><div class="content"><a class="title" href="/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/" title="Docker Compose学习">Docker Compose学习</a><time datetime="2023-08-27T15:34:50.000Z" title="发表于 2023-08-27 23:34:50">2023-08-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Dockerfile学习"/></a><div class="content"><a class="title" href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习">Dockerfile学习</a><time datetime="2023-08-27T15:34:37.000Z" title="发表于 2023-08-27 23:34:37">2023-08-27</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2024 By Fei</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">欢迎进入<a href="tengfei2233.gitee.io/">飞の博客</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/utils.min.js"></script><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/main.min.js"></script><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/tw_cn.min.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.1.1/instantpage.min.js" type="module"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.staticfile.org/pangu/4.0.7/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: '0kbeJfFlvhvkYfqMqwwVCx1a-gzGzoHsz',
      appKey: 'rziWUw1MTHMW7d9eeCQzu9HV',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.staticfile.org/valine/1.5.1/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="ribbon" src="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/search/local-search.min.js"></script></div></body></html>